package com.ruoyi.web.controller.staff;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.staff.domain.Staff;
import com.ruoyi.staff.service.IStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 职工管理Controller
 * 
 * @author ruoyi
 * @date 2025-02-22
 */
@RestController
@RequestMapping("/staff/staff")
public class StaffController extends BaseController
{
    @Autowired
    private IStaffService staffService;

    /**
     * 查询职工管理列表
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:list')")
    @GetMapping("/list")
    public TableDataInfo list(Staff staff)
    {
        startPage();
        List<Staff> list = staffService.selectStaffList(staff);
        return getDataTable(list);
    }

    /**
     * 导出职工管理列表
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:export')")
    @Log(title = "职工管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Staff staff)
    {
        List<Staff> list = staffService.selectStaffList(staff);
        ExcelUtil<Staff> util = new ExcelUtil<Staff>(Staff.class);
        util.exportExcel(response, list, "职工管理数据");
    }

    /**
     * 获取职工管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(staffService.selectStaffById(id));
    }

    /**
     * 新增职工管理
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:add')")
    @Log(title = "职工管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Staff staff)
    {
        return toAjax(staffService.insertStaff(staff));
    }

    /**
     * 修改职工管理
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:edit')")
    @Log(title = "职工管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Staff staff)
    {
        return toAjax(staffService.updateStaff(staff));
    }

    /**
     * 删除职工管理
     */
    @PreAuthorize("@ss.hasPermi('staff:staff:remove')")
    @Log(title = "职工管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(staffService.deleteStaffByIds(ids));
    }
}
